package com.yanqu.road.server.manager.chefduel;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.chefduel.process3.ChefDuel3BanquetReward;
import com.yanqu.road.entity.enums.activity.chefDuel.eChefDuelActivityType;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.TempCrossMgr;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.CrossRelationActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.date.DateHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CrossChefDuelMgr extends TempCrossMgr {

    private static Logger logger = LogManager.getLogger(CrossChefDuelMgr.class.getName());

    private static Map<Integer, CrossChefDuel> crossChefDuelMap = new ConcurrentHashMap<>();//活动map

    private static Map<Integer, CrossChefDuel2> crossChefDuel2Map = new ConcurrentHashMap<>();//厨神对决2活动map

    private static Map<Integer, CrossChefDuel3> crossChefDuel3Map = new ConcurrentHashMap<>();//厨神对决3活动map

    private static Map<Integer, Object> activityLock;


    //阶段1晋级阶段2(支持不同跨服导活动)
    public static int windUpChefDuel1User(int activityId, Map<Integer, Long> userMap) {
        ActivityInfo ck1Ac = CrossChefDuelActivityMgr.getOpenActivityInfo(activityId);
        List<ActivityInfo> activityInfoList = CrossChefDuelActivityMgr.getOpenActivityInfoList(eActivityType.ChefDuel.getValue(), eChefDuelActivityType.Phase2.getChildType());
        for (ActivityInfo activityInfo : activityInfoList) {
            //阶段2活动和阶段1活动有重叠或者只有一个活动
            if (activityInfoList.size() == 1 || CrossChefDuelActivityMgr.isActivityContain(ck1Ac, activityInfo)) {
                synchronized (getActivityLock(activityId)) {
                    CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityInfo.getActivityId());
                    if (crossChefDuel2 != null) {
                        crossChefDuel2.addPromotionUser(userMap);
                        return activityInfo.getActivityId();
                    }
                }
            }
        }
        return 0;
    }

    //阶段2晋级阶段3
    public static int windUpChefDuel2User(int activityId, Map<Integer, Long> userMap) {
        ActivityInfo ck1Ac = CrossChefDuelActivityMgr.getOpenActivityInfo(activityId);
        List<ActivityInfo> activityInfoList = CrossChefDuelActivityMgr.getOpenActivityInfoList(eActivityType.ChefDuel.getValue(), eChefDuelActivityType.Phase3.getChildType());
        for (ActivityInfo activityInfo : activityInfoList) {
            //阶段3活动和阶段1活动有重叠或者只有一个活动
            if (activityInfoList.size() == 1 || CrossChefDuelActivityMgr.isActivityContain(ck1Ac, activityInfo)) {
                synchronized (getActivityLock(activityId)) {
                    CrossChefDuel3 crossCookBo3 = getCrossChefDuel3(activityInfo.getActivityId());
                    if (crossCookBo3 != null) {
                        crossCookBo3.addPromotionUser(userMap);
                        return activityInfo.getActivityId();
                    }
                }
            }
        }
        return 0;
    }
    /*↑↑↑↑晋级↑↑↑↑↑↑*/

    public static String getChefDuel3BanquetTimes(int activityId, String param) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                return crossChefDuel3.getChefDuel3BanquetTimes(param);
            }
        return "";
    }

    public static String getChefDuel3BanquetUserCount(int activityId, String param) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                return crossChefDuel3.getChefDuel3BanquetUserCount(param);
            }
        return "";
    }

    public static void getBanquetJoiner(int activityId, long serverId, long userId, long homeUserId, int banquetId, int page, int num) {
        CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
        if (crossChefDuel3 != null) {
            crossChefDuel3.getBanquetJoiner(serverId, userId, homeUserId, banquetId, page, num);
        }
    }

    public static void getUserBanquet(int activityId, long serverId, long userId, long homeUserId) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                crossChefDuel3.getUserBanquet(serverId, userId, homeUserId);
            }
    }

    public static void addPromotion3User(int activityId, long serverId, List<ChefDuelProto.CrossChefDuelWindUpCookerTempMsg> userListMsg) {
        synchronized (getActivityLock(activityId)) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                crossChefDuel3.addPromotionUser(serverId, userListMsg);
            }
        }
    }

    public static CrossChefDuel3 getCrossChefDuel3IfNull(int activityId) {
        return crossChefDuel3Map.get(activityId);
    }

    private static CrossChefDuel3 getCrossChefDuel3(int activityId) {
        if (crossChefDuel3Map.containsKey(activityId)) {
            return crossChefDuel3Map.get(activityId);
        } else {
            CrossChefDuelActivityMgr.reloadActivityInfo(activityId);
            ActivityInfo acInfo = CrossChefDuelActivityMgr.getOpenActivityInfo(activityId);
            if (acInfo != null) {
                if(acInfo.getType() != eActivityType.ChefDuel.getValue()){
                    return null;
                }
                CrossChefDuel3 crossChefDuel3 = new CrossChefDuel3(acInfo);
                if (crossChefDuel3.init()) {
                    crossChefDuel3Map.put(activityId, crossChefDuel3);
                } else {
                    logger.error("跨服厨神对决3活动" + activityId + "加载失败");
                }
                return crossChefDuel3Map.get(activityId);
            }
            return null;
        }
    }

    public static void syncCooker3Table(int activityId, long serverId, long userId, long homeUserId) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                crossChefDuel3.syncCooker3Table(serverId, userId, homeUserId);
            }
    }

    public static void openBanquet(int activityId, long serverId, long userId, int itemId) {
        synchronized (getActivityLock(activityId)) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                crossChefDuel3.openBanquet(serverId, userId, itemId);
            }
        }
    }

    public static int joinBanquet(int activityId, long serverId, long joinUserId, long homeUserId, int banquetId) {
        CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
        if (crossChefDuel3 != null) {
            return crossChefDuel3.joinBanquet(serverId, joinUserId, homeUserId, banquetId);
        }
        return GameErrorCode.E_ACTIVITY_NO_FOUND;
    }

    public static ChefDuel3BanquetReward getBanquetReward(int activityId, long userId, int no) {
        ChefDuel3BanquetReward cookBoyBanquetReward = new ChefDuel3BanquetReward();
            CrossChefDuel3 crossCookBo3y = getCrossChefDuel3(activityId);
            if (crossCookBo3y != null) {
                return crossCookBo3y.getBanquetReward(userId, no);
            }
        cookBoyBanquetReward.setRet(GameErrorCode.E_RELATION_ACTIVITY_NO_IN_TIME);
        return cookBoyBanquetReward;
    }

    /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓厨神对决二↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓1*/
    public static int joinTable(int activityId, long serverId, long joinUserId, long homeId, int tableId, int spoonId, int trueActivityId, int campId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            return crossChefDuel2.joinTable(serverId, joinUserId, homeId, tableId, spoonId, trueActivityId, campId);
        }
        return GameErrorCode.E_ACTIVITY_NO_FOUND;
    }

    public static int preJoinTable(int activityId, long serverId, long joinUserId, long homeId, int tableId, int spoonId, int trueActivityId, int campId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            return crossChefDuel2.preJoinTable(serverId, joinUserId, homeId, tableId, spoonId, trueActivityId, campId);
        }
        return GameErrorCode.E_ACTIVITY_NO_FOUND;
    }

    public static int preJoinOtherTable(int activityId, long serverId, long joinUserId, long homeId, int tableId, int spoonId, int trueActivityId, int campId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            return crossChefDuel2.preJoinOtherTable(serverId, joinUserId, homeId, tableId, spoonId, trueActivityId, campId);
        }
        return GameErrorCode.E_ACTIVITY_NO_FOUND;
    }

    public static List<Integer> getUserForbiddenSpoonIdList(int activityId, long userId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            return crossChefDuel2.getUserForbiddenSpoonIdList(userId);
        }
        return new ArrayList<>();
    }

    public static void serveDish(int activityId, long serverId, long userId, Map<Integer, Integer> dishMap) {
        synchronized (getActivityLock(activityId)) {
            CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
            if (crossChefDuel2 != null) {
                crossChefDuel2.serveDish(serverId, userId, dishMap);
            }
        }
    }

    public static void syncCookerHomeTable(int activityId, long serverId, long userId, long homeUser, int page, int num) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.syncCookerHomeTable(serverId, userId, homeUser, page, num);
        }
    }

    public static void getCookerTable(int activityId, long serverId, long userId, long homeUser, int tableId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getCookerTable(serverId, userId, homeUser, tableId);
        }
    }

    public static void syncCookerTable(int activityId, long serverId, long userId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.syncCookerTable(serverId, userId);
        }
    }

    public static void getRecord(int activityId, long serverId, long userId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getRecord(serverId, userId);
        }
    }

    public static void getUnionRelation(int activityId, long serverId, long userId, List<Long> unionList, List<Long> relationList) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getUnionRelation(serverId, userId, unionList, relationList);
        }
    }
    public static void getSearchAll(int activityId, long serverId, long userId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getSearchAll(serverId, userId);
        }
    }

    public static void searchUser(int activityId, long serverId, long userId, String searchUserId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.searchUser(serverId, userId, searchUserId);
        }
    }


    public static void uploadChefDuel2Score(ChefDuelProto.CrossChefDuel2ScoreUploadMsg reqMsg) {
        int activityId = reqMsg.getActivityId();
        CrossChefDuel2 chefDuel2 = getCrossChefDuel2IfNull(activityId);
        if(chefDuel2 != null){
            chefDuel2.uploadChefDuelScore(reqMsg.getScoreList());
        }
    }

    public static void uploadChefDuel3Score(ChefDuelProto.CrossChefDuel2ScoreUploadMsg reqMsg) {
        int activityId = reqMsg.getActivityId();
        CrossChefDuel3 chefDuel3 = getCrossChefDuel3IfNull(activityId);
        if(chefDuel3 != null){
            chefDuel3.uploadChefDuelScore(reqMsg.getScoreList());
        }
    }

    /**
     * 一阶段晋升二阶段
     */
    public static void addPromotion2User(int activityId, long serverId, List<ChefDuelProto.CrossChefDuelWindUpCookerTempMsg> userListMsg) {
        synchronized (getActivityLock(activityId)) {
            CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
            if (crossChefDuel2 != null) {
                crossChefDuel2.addPromotionUser(serverId, userListMsg);
            }
        }
    }

    //获取随机可以加入宴会的用户
    public static void getRandomCanJoinUser(int activityId, long serverId, long userId, long nowUserId,List<Integer> spoonIdList) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getRandomCanJoinUser(serverId, userId, nowUserId,spoonIdList);
        }
    }

    //禁止汤勺进食
    public static void forbidSpoon(int activityId, long serverId, long userId, List<Integer> forbidSpoonIdList) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.forbidSpoon(serverId, userId, forbidSpoonIdList);
        }
    }

    public static CrossChefDuel2 getCrossChefDuel2IfNull(int activityId) {
        return crossChefDuel2Map.get(activityId);
    }

    private static CrossChefDuel2 getCrossChefDuel2(int activityId) {
        if (crossChefDuel2Map.containsKey(activityId)) {
            return crossChefDuel2Map.get(activityId);
        } else {
            CrossChefDuelActivityMgr.reloadActivityInfo(activityId);
            ActivityInfo acInfo = CrossChefDuelActivityMgr.getOpenActivityInfo(activityId);
            if (acInfo != null) {
                if(acInfo.getType() != eActivityType.ChefDuel.getValue()){
                    return null;
                }
                CrossChefDuel2 crossChefDuel2 = new CrossChefDuel2(acInfo);
                if (crossChefDuel2.init()) {
                    crossChefDuel2Map.put(activityId, crossChefDuel2);
                } else {
                    logger.error("跨服厨神对决2活动" + activityId + "加载失败");
                }
                return crossChefDuel2Map.get(activityId);
            }
        }
        return null;
    }

    public static void addChefDuel2Horse(int activityId, long serverId, long userId, int dishId, long time) {
            CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
            if (crossChefDuel2 != null) {
                crossChefDuel2.addChefDuel2Horse(serverId, userId, dishId, time);
            }
    }

    private static CrossChefDuel getCrossChefDuel(int activityId) {
        if (crossChefDuelMap.containsKey(activityId)) {
            return crossChefDuelMap.get(activityId);
        } else {
            CrossChefDuelActivityMgr.reloadActivityInfo(activityId);
            ActivityInfo acInfo = CrossChefDuelActivityMgr.getOpenActivityInfo(activityId);
            if (acInfo != null) {
                CrossChefDuel crossChefDuel = new CrossChefDuel(acInfo);
                if (crossChefDuel.init()) {
                    crossChefDuelMap.put(activityId, crossChefDuel);
                } else {
                    logger.error("跨服厨神对决活动" + activityId + "加载失败");
                }
                return crossChefDuelMap.get(activityId);
            }
        }
        return null;
    }


    /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓通用↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓1*/
    //独立出来，降低同步频率
    public static void winUpTimerTask(){
        for (CrossChefDuel crossChefDuel : crossChefDuelMap.values()) {
            crossChefDuel.activityEndWindUp();
        }

        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            crossChefDuel2.activityEndWindUp();
        }
    }

    public static void commonTimerTask() {
        int currentSecond = DateHelper.getCurrentSecond();
        for (CrossChefDuel crossChefDuel : crossChefDuelMap.values()) {
            synchronized (getActivityLock(crossChefDuel.getActivityId())) {
                crossChefDuel.timerTask();
            }
        }

        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            synchronized (getActivityLock(crossChefDuel2.getActivityId())) {
                crossChefDuel2.timerTask();
            }
            if (currentSecond >= crossChefDuel2.getActivityInfo().getEndTime() + 5 * 60) {
                crossChefDuel2.sendAutoJoinSpoonRest(crossChefDuel2.getActivityInfo().getActivityId()); // 活动过期将设置的自动回访汤勺返回
            }
        }

        for (CrossChefDuel3 crossChefDuel3 : crossChefDuel3Map.values()) {
            crossChefDuel3.timerTask();
        }

    }

    public static void timerTaskBoy2() {
        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            if(ActivityMgr.activityInTime(crossChefDuel2.getActivityInfo())){
                if(!crossChefDuel2.getActivityInfo().getServerIdList2().isEmpty()){
                    List<Long> needSyncServerIdList = crossChefDuel2.getNeedSyncServerIdList();
                    if(!needSyncServerIdList.isEmpty()){
                        crossChefDuel2.setSyncServerIdList(new ConcurrentHashSet<>(needSyncServerIdList));
                    }
                }
            }
        }

        //阵营奖励补发
        int currentSecond = DateHelper.getCurrentSecond();
        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            if(currentSecond > crossChefDuel2.getActivityInfo().getEndShowTime() + DateHelper.HOUR_SECONDS){
                crossChefDuel2.sendCampRankReward();
            }
        }

        //阵营奖励补发
        for (CrossChefDuel3 crossChefDuel3 : crossChefDuel3Map.values()) {
            if(currentSecond > crossChefDuel3.getActivityInfo().getEndShowTime() + DateHelper.HOUR_SECONDS){
                crossChefDuel3.sendCampRankReward();
            }
        }
    }

    public static void syncChefDuel3LoginData(int activityId, long serverId, long userId) {
            CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
            if (crossChefDuel3 != null) {
                crossChefDuel3.syncLoginData(serverId, userId);
            }
    }

    public static void noticeTimerTask() {
        for (CrossChefDuel3 crossChefDuel3 : crossChefDuel3Map.values()) {
            crossChefDuel3.noticeTimerTask();
        }
    }

    private static synchronized Object getActivityLock(int activityId) {
        if (activityLock == null) {
            activityLock = new ConcurrentHashMap<>();
        }
        if (!activityLock.containsKey(activityId)) {
            activityLock.put(activityId, new Object());
        }
        return activityLock.get(activityId);
    }

    public static void loadActivity(int activityId) {
        synchronized (getActivityLock(activityId)) {
            ActivityInfo acInfo = CrossChefDuelActivityMgr.getOpenActivityInfo(activityId);
            if (acInfo != null) {
                if (acInfo.getChildType() == eChefDuelActivityType.Phase1.getChildType()) {
                    if (!crossChefDuelMap.containsKey(activityId)) {
                        CrossChefDuel crossChefDuel = new CrossChefDuel(acInfo);
                        if (crossChefDuel.init()) {
                            crossChefDuelMap.put(activityId, crossChefDuel);
                            logger.debug("跨服厨神对决1活动" + activityId + "加载到跨服");
                        } else {
                            logger.error("跨服厨神对决1活动" + activityId + "加载失败");
                        }
                    } else {
                        crossChefDuelMap.get(activityId).setActivityInfo(acInfo);
                    }
                } else if (acInfo.getChildType() == eChefDuelActivityType.Phase2.getChildType()) {
                    if (!crossChefDuel2Map.containsKey(activityId)) {
                        CrossChefDuel2 crossChefDuel2 = new CrossChefDuel2(acInfo);
                        if (crossChefDuel2.init()) {
                            crossChefDuel2Map.put(activityId, crossChefDuel2);
                        } else {
                            logger.error("跨服厨神对决2活动" + activityId + "加载失败");
                        }
                    } else {
                        crossChefDuel2Map.get(activityId).setActivityInfo(acInfo);
                    }
                } else if (acInfo.getChildType() == eChefDuelActivityType.Phase3.getChildType()) {
                    if (!crossChefDuel3Map.containsKey(activityId)) {
                        CrossChefDuel3 crossChefDuel3 = new CrossChefDuel3(acInfo);
                        if (crossChefDuel3.init()) {
                            crossChefDuel3Map.put(activityId, crossChefDuel3);
                        } else {
                            logger.error("跨服厨神对决3活动" + activityId + "加载失败");
                        }
                    } else {
                        crossChefDuel3Map.get(activityId).setActivityInfo(acInfo);
                    }
                }
            }
        }
    }

    public static void removeActivity() {
        Map<Integer, ActivityInfo> activityInfoMap = CrossRelationActivityMgr.getOpenActivityInfoMap(eActivityType.ChefDuel.getValue());
        for (CrossChefDuel crossChefDuel : crossChefDuelMap.values()) {
            if (!activityInfoMap.containsKey(crossChefDuel.getActivityId())) {
                removeData(crossChefDuel.getActivityId());
            }
        }
        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            if (!activityInfoMap.containsKey(crossChefDuel2.getActivityId())) {
                removeData(crossChefDuel2.getActivityId());
            }
        }
        for (CrossChefDuel3 crossChefDuel3 : crossChefDuel3Map.values()) {
            if (!activityInfoMap.containsKey(crossChefDuel3.getActivityId())) {
                removeData(crossChefDuel3.getActivityId());
            }
        }
    }

    private static void removeData(int activityId) {
        crossChefDuelMap.remove(activityId);
        crossChefDuel2Map.remove(activityId);
        crossChefDuel3Map.remove(activityId);
        activityLock.remove(activityId);
        logger.error("remove chefduel activity:{}", activityId);
    }

    public static void checkDishStatus(int activityId, long serverId, List<ChefDuelProto.NeedCheckChefDuel2DishMsg> dishList) {
        synchronized (getActivityLock(activityId)) {
            CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
            if (crossChefDuel2 != null) {
                crossChefDuel2.checkDishStatus(serverId,dishList);
            }
        }
    }

    public static void syncActivityBack(int activityId, long serverId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null){
            crossChefDuel2.syncActivityBack(serverId);
        }
    }

    //参加赴宴范围内的，来补充记录
    public static void syncJoinDataFromOtherActivity(int activityId, long homeUserId, long joinUserId, int otherActivityId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null){
            crossChefDuel2.newJoin(homeUserId, joinUserId, otherActivityId);
        }
    }

    public static int selectCampId(int activityId, long serverId, long playerId, int campId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null) {
            return crossChefDuel2.selectCampId(serverId, playerId, campId);
        }
        return 0;
    }

    public static int selectCampId3(int activityId, long serverId, long playerId, int campId) {
        CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
        if(crossChefDuel3 != null) {
            return crossChefDuel3.selectCampId(serverId, playerId, campId);
        }
        return 0;
    }

    public static int campPopNum(int activityId, long serverId, long playerId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null) {
            return crossChefDuel2.campPopNum(serverId, playerId);
        }
        return 0;
    }

    public static int campPopNum3(int activityId, long serverId, long playerId) {
        CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
        if(crossChefDuel3 != null) {
            return crossChefDuel3.campPopNum(serverId, playerId);
        }
        return 0;
    }

    public static void timerTask2() {
        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            if (ActivityMgr.activityInShowTime(crossChefDuel2.getActivityInfo())) {
                crossChefDuel2.timerTask4Stat();
            }
        }
    }

    public static void timerTask3() {
        for (CrossChefDuel3 crossChefDuel3 : crossChefDuel3Map.values()) {
            if (ActivityMgr.activityInShowTime(crossChefDuel3.getActivityInfo())) {
                crossChefDuel3.timerTask4Stat();
            }
        }
    }

    public static void closeTable(long serverId, long playerId, int activityId, int serDishId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null) {
            crossChefDuel2.closeTable(serverId, playerId, serDishId);
        }
    }

    public static void closeAllTable(long serverId, long playerId, int activityId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null) {
            crossChefDuel2.closeAllTable(serverId, playerId);
        }
    }

    public static void getChefDuel2CampRank(long serverId, long playerId, int activityId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if(crossChefDuel2 != null) {
            int ret = crossChefDuel2.getChefDuel2CampRank(serverId, playerId);
            if (ret != 0) {
                ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.Builder builder = ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.newBuilder();
                builder.setRet(ret);
                YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.U_CHEF_DUEL2_CAMP_RANK_REWARD, builder);
                MessageHelper.sendPacket(serverId, playerId, message);
            }
        }
    }
    public static void getChefDuel3CampRank(long serverId, long playerId, int activityId) {
        CrossChefDuel3 crossChefDuel3 = getCrossChefDuel3(activityId);
        if(crossChefDuel3 != null) {
            int ret = crossChefDuel3.getChefDuel3CampRank(serverId, playerId);
            if (ret != 0) {
                ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.Builder builder = ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.newBuilder();
                builder.setRet(ret);
                YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.U_CHEF_DUEL3_CAMP_RANK_REWARD, builder);
                MessageHelper.sendPacket(serverId, playerId, message);
            }
        }
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    public boolean save() {
        for (CrossChefDuel crossChefDuel : crossChefDuelMap.values()) {
            crossChefDuel.save();
        }
        for (CrossChefDuel2 crossChefDuel2 : crossChefDuel2Map.values()) {
            crossChefDuel2.save();
        }
        for (CrossChefDuel3 crossChefDuel3 : crossChefDuel3Map.values()) {
            crossChefDuel3.save();
        }
        return true;
    }

    public boolean init() throws Exception {
        return reload();
    }

    public boolean stop() {
        return false;
    }

    /**
     * 预留接口
     */
    public static void repair(int activityId) {
        CrossChefDuel crossChefDuel = crossChefDuelMap.get(activityId);
        if (crossChefDuel != null) {
            crossChefDuel.repair();
        }
        CrossChefDuel2 crossChefDuel2 = crossChefDuel2Map.get(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.repair();
        }
        CrossChefDuel3 crossChefDuel3 = crossChefDuel3Map.get(activityId);
        if (crossChefDuel3 != null) {
            crossChefDuel3.repair();
        }
    }

    public boolean removeExpireData(){
        List<Integer> cook1List = new ArrayList<>();
        List<Integer> cook2List = new ArrayList<>();
        List<Integer> cook3List = new ArrayList<>();
        long nowTime = System.currentTimeMillis();
        for(Integer activityId : crossChefDuelMap.keySet()){
            CrossChefDuel data = crossChefDuelMap.get(activityId);
            if(data.getActivityInfo() == null || (nowTime > data.getActivityInfo().getEndShowTime()  * 1000 + DateHelper.DAY_MILLIONS)){
                cook1List.add(activityId);
            }
        }
        for(Integer activityId : crossChefDuel2Map.keySet()){
            CrossChefDuel2 data = crossChefDuel2Map.get(activityId);
            if(data.getActivityInfo() == null || (nowTime > data.getActivityInfo().getEndShowTime()  * 1000 + DateHelper.DAY_MILLIONS)){
                cook2List.add(activityId);
            }
        }
        for(Integer activityId : crossChefDuel3Map.keySet()){
            CrossChefDuel3 data = crossChefDuel3Map.get(activityId);
            if(data.getActivityInfo() == null || (nowTime > data.getActivityInfo().getEndShowTime()  * 1000 + DateHelper.DAY_MILLIONS)){
                cook3List.add(activityId);
            }
        }
        for(Integer activityId : cook1List){
            crossChefDuelMap.remove(activityId);
        }
        for(Integer activityId : cook2List){
            crossChefDuel2Map.remove(activityId);
        }
        for(Integer activityId : cook3List){
            crossChefDuel3Map.remove(activityId);
        }

        return true;
    }

    /**
     * 获取自动回访记录
     *
     * @param activityId 活动ID
     * @param serverId   服务器ID
     * @param userId     用户ID
     */
    public static void getAutoJoinRecord(int activityId, long serverId, long userId) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getAutoJoinRecord(serverId, userId);
        }
    }

    /**
     * 获取摊主可试吃数量
     *
     * @param serverId 回发游戏服ID
     * @param activityId 活动ID
     * @param reqMsg reqMsg
     */
    public static void getTasteTableCnt(long serverId, int activityId, ChefDuelProto.CrossChefDuel2GetTasteTableCntMsg reqMsg) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.getTasteTableCnt(serverId, reqMsg);
        }
    }

    /**
     * 自动回访试吃
     *
     */
    public static void autoJoinTaste(long serverId, int activityId, ChefDuelProto.CrossChefDuel2AutoJoinTasteMsg reqMsg) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.autoJoinTaste(serverId, reqMsg);
        }
    }

    /**
     * 自动回访
     *
     */
    public static void syncAutoJoinData(long serverId, int activityId, ChefDuelProto.CrossChefDuel2SyncAutoJoinDataMsg reqMsg) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.syncAutoJoinData(serverId, reqMsg);
        }
    }

    /**
     * 自动回访
     *
     */
    public static void syncAutoJoinSpoon(long serverId, int activityId, ChefDuelProto.CrossChefDuel2SyncAutoJoinSpoonMsg reqMsg) {
        CrossChefDuel2 crossChefDuel2 = getCrossChefDuel2(activityId);
        if (crossChefDuel2 != null) {
            crossChefDuel2.syncAutoJoinSpoon(serverId, reqMsg);
        }
    }
}
